/**
 * $Id: interp.h,v 1.11 2006/10/31 21:20:29 gtang Exp $
 */

/*
 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
 * Copyright (c) 2000-2006 Baylor College of Medicine
 * 
 * This software is issued under a joint BSD/GNU license. You may use the
 * source code in this file under either license. However, note that the
 * complete EMAN2 and SPARX software packages have some GPL dependencies,
 * so you are responsible for compliance with the licenses of these packages
 * if you opt to use BSD licensing. The warranty disclaimer below holds
 * in either instance.
 * 
 * This complete copyright notice must be included in any revised version of the
 * source code. Additional authorship citations may be added, but existing
 * author citations must be preserved.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * */

#ifndef eman__interp_h__
#define eman__interp_h__

#include <cmath>

namespace EMAN
{

	/** Interp defines the interpolation function used to generate
     * a e^-x^4 function in real space. Used for Fourier interpolation
     */
	class Interp
	{
	  public:
		static float get_hyperg(int i)
		{
			return HYPERGEOM[i];
		}

		static float hyperg(float v)
		{
			if (v < 0 || v > 4.998f) {
				return 0;
			}
			float r = v / 0.001f;
			int a = (int) floor(r);
			r -= a;
			return (float)(-(HYPERGEOM[a] * (1.0 - r) + HYPERGEOM[a + 1] * r));
		}

		static float *get_gimx()
		{
			if (!gimx) {
				init_gimx();
			}
			return gimx;
		}

	  private:
		static void init_gimx();

	  private:
		static float HYPERGEOM[];
		static float *gimx;
	};
}

#endif
